#include<iostream>
#include<string>
using namespace std;

class Solution {
public:
    void reserve_(string& str,int begin,int end)
    {
        while(begin<end)
        {
            char temp=str[begin];
            str[begin]=str[end];
            str[end]=temp;
            begin++;
            end--;
        }
    }
    string reverseStr(string s, int k) 
    {
        int i=0;
        while(i<=s.size())
        {
            if(i+2*k<=s.size())
            {
                reserve_(s,i,i+k-1);
                i+=2*k;
            }
            else if(i+k<s.size())
            {
                reserve_(s,i,i+k-1);
                return s;
            }
            else
            {
                reserve_(s,i,s.size()-1);
                return s;
            }
        }
        return s;
    }
};